package com.wcgksoft.controller.work_plan.work_plan_week;

import com.wcgksoft.common.util.FileUpload;
import com.wcgksoft.common.util.Layui;
import com.wcgksoft.common.util.comm.StringUtils;
import com.wcgksoft.entity.GreedLand.GreedLand;
import com.wcgksoft.entity.Work_plan.Work_plan_week.Plan_week_info;
import com.wcgksoft.entity.Work_plan.Work_plan_week.Plan_week_summary;
import com.wcgksoft.entity.Work_plan.Work_plan_week.Work_plan_week;
import com.wcgksoft.entity.Work_plan.Work_plan_week.Work_plan_week_img;
import com.wcgksoft.service.GreedLand.GreedlandService;
import com.wcgksoft.service.Work_paln.Work_paln_week.Plan_week_infoServie;
import com.wcgksoft.service.Work_paln.Work_paln_week.Plan_week_summaryService;
import com.wcgksoft.service.Work_paln.Work_paln_week.Work_Plan_week_imgService;
import com.wcgksoft.service.Work_paln.Work_paln_week.Work_plan_weekService;
import net.sf.json.JSONObject;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 周权
 * @Date: 2020/03/25/10:17
 * @Description:工作周计划
 */
@Controller
@RequestMapping(value = "system/work_plan_week")
public class Work_plan_weekController {
    @Autowired
    private Work_plan_weekService work_paln_weekService;
    @Autowired
    private Plan_week_infoServie plan_week_infoServie;
    @Autowired
    private Plan_week_summaryService plan_week_summaryService;
    @Autowired
    private GreedlandService greedlandService;
    @Autowired
    private Work_Plan_week_imgService work_plan_week_imgService;

    /*
     * @Author: 周权
     * @Description:获取当前管理角色下激活的绿地
     * @Param:
     * @create: 2020/3/22 19:24
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "findArea")
    public Layui findArea(@RequestParam(value = "area_id", required = false) Integer area_id){
        DetachedCriteria criteria = DetachedCriteria.forClass(GreedLand.class);
        criteria.add(Restrictions.eq("state", 0));
        String s = String.valueOf(area_id);
        criteria.add(Restrictions.eq("areaid", s));
        List<GreedLand> byConditions = greedlandService.findByConditions(criteria);
        return Layui.data(1, "查询成功", greedlandService.getTotalCount(), byConditions);
    }

    /*
     * @Author: 周权
     * @Description:周计划详情回显
     * @Param:
     * @create: 2020/3/22 22:03
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "findInfo")
    public Layui findInfo(@RequestParam(value = "i_pid") Integer i_pid) {
        DetachedCriteria criteria = DetachedCriteria.forClass(Plan_week_info.class);
        criteria.add(Restrictions.eq("i_pid", i_pid));
        List<Plan_week_info> byConditions = plan_week_infoServie.findByConditions(criteria);
        for (int i = 0; i < byConditions.size(); i++) {
            GreedLand byId = greedlandService.findById(byConditions.get(i).getI_gid());
            byConditions.get(i).setGreedLand(byId);
        }
        return Layui.data(0, "查询成功", plan_week_infoServie.getTotalCount(), byConditions);
    }

    /*
     * @Author: 周权
     * @Description: 周计划总结回显
     * @Param:
     * @create: 2020/3/23 14:28
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "findSummary")
    public Layui findSummary(@RequestParam(value = "su_pid") Integer su_pid) {
        DetachedCriteria criteria = DetachedCriteria.forClass(Plan_week_summary.class);
        criteria.add(Restrictions.eq("su_pid", su_pid));
        List<Plan_week_summary> byConditions = plan_week_summaryService.findByConditions(criteria);
        return Layui.data(0, "查询成功", plan_week_summaryService.getTotalCount(), byConditions);
    }

    /*
     * @Author: 周权
     * @Description:周计划列表页面layui的table加载数据
     * @Param:
     * @create: 2020/3/22 22:17
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "findAll")
    public Layui findAll(@RequestParam(value = "d_eid") Integer d_eid,
                         @RequestParam(value = "d_area_id") Integer d_area_id,
                         @RequestParam(value = "page", required = false) Integer page,
                         @RequestParam(value = "limit", required = false) Integer limit,
                         @RequestParam(value = "d_name",required = false) String d_name,
                         @RequestParam(value = "starttime",required = false) String starttime,
                         @RequestParam(value = "endtime",required = false) String endtime) throws ParseException {
        DetachedCriteria criteria = DetachedCriteria.forClass(Work_plan_week.class);
        criteria.add(Restrictions.eq("d_eid", d_eid));
        criteria.add(Restrictions.eq("d_area_id", d_area_id));
        criteria.add(Restrictions.eq("d_state", 0));
        if (StringUtils.isNotEmpty(d_name)){
            criteria.add(Restrictions.like("d_name", d_name, MatchMode.ANYWHERE));
        }
        if ((null!=starttime&&!"".equals(starttime)) && (null!=endtime&&!"".equals(endtime))) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date parse = sdf.parse(starttime+" 00:00:00");
            Date parse2 = sdf.parse(endtime+" 23:59:99");
            criteria.add(Restrictions.between("d_createDate", parse, parse2));
        }
        if ((null!=starttime&&!"".equals(starttime)) && (null==endtime||"".equals(endtime))){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date parse = sdf.parse(starttime+" 00:00:00");
            Date parse2 = sdf.parse("2099-12-01 23:59:99");
            criteria.add(Restrictions.between("d_createDate", parse, parse2));
        }
        if ((null!=endtime&&!"".equals(endtime)) && (null==starttime||"".equals(starttime))){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date parse = sdf.parse(endtime+" 23:59:99");
            Date parse2 = sdf.parse("1997-12-01 00:00:00");
            criteria.add(Restrictions.between("d_createDate", parse2, parse));
        }
        List<Work_plan_week> byConditions = work_paln_weekService.findByConditions(criteria,page,limit);
        return Layui.data(0, "查询成功", work_paln_weekService.getTotalCount(), byConditions);
    }

    /*
     * @Author: 周权
     * @Description:月报添加/修改
     * @Param:
     * @create: 2020/3/22 22:23
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "update")
    @Transactional
    public Layui update(@RequestParam(value = "data", required = false) String data,
                        @RequestParam(value = "greenlands")String greenlands,
                        @RequestParam(value = "contents")String contents,
                        @RequestParam(value = "palns")String palns,
                        @RequestParam(value = "greenlandss")String greenlandss,
                        @RequestParam(value = "contentss")String contentss,
                        @RequestParam(value = "palnss")String palnss){
        JSONObject param = JSONObject.fromObject(data);
        if (param == null) {
            return Layui.data(1, "请求格式有误", 0, null);
        } else {
            String id1 = String.valueOf(param.get("id"));
            if(null==id1||id1.equals("")){
                Work_plan_week work_plan_week = (Work_plan_week) JSONObject.toBean(JSONObject.fromObject(data), Work_plan_week.class);
                work_plan_week.setD_createDate(new Date());
                work_plan_week.setD_state(0);
                work_paln_weekService.save(work_plan_week);
                if (null!=greenlands){
                    String[] greenlandlist = greenlands.split(",");
                    String[] contentlist = contents.split(",");
                    String[] palnlist = palns.split(",");
                    if (greenlandlist.length>0){
                        for (int i = 0; i < greenlandlist.length; i++) {
                            if ((null==greenlandlist[i]||greenlandlist[i].equals("")||greenlandlist[i]=="")&&(null==contentlist[i]||contentlist[i].equals("")||contentlist[i]=="")&&(null==palnlist[i]||palnlist[i].equals("")||palnlist[i]=="")){
                                continue;
                            }else{
                                Plan_week_info plan_week_info = new Plan_week_info();
                                plan_week_info.setI_pid(work_plan_week.getId());
                                plan_week_info.setI_gid(Integer.parseInt(greenlandlist[i]));
                                plan_week_info.setI_content(contentlist[i]);
                                plan_week_info.setI_comp(palnlist[i]);
                                plan_week_infoServie.save(plan_week_info);
                            }

                        }
                    }
                }
                return Layui.data(0, "添加成功", 1, Layui.addList(work_plan_week));
            }else{
                Work_plan_week work_plan_week = (Work_plan_week) JSONObject.toBean(JSONObject.fromObject(data), Work_plan_week.class);
                work_plan_week.setD_createDate(new Date());
                work_plan_week.setD_state(0);
                work_paln_weekService.saveOrUpdate(work_plan_week);
                if (null!=greenlands){
                    DetachedCriteria criteria = DetachedCriteria.forClass(Plan_week_info.class);
                    criteria.add(Restrictions.eq("i_pid", work_plan_week.getId()));
                    List<Plan_week_info> byConditions = plan_week_infoServie.findByConditions(criteria);
                    if(null!=byConditions){
                        for(Plan_week_info plan_week_info:byConditions){
                            plan_week_infoServie.deleteCass(plan_week_info);
                        }
                        String[] greenlandlist = greenlands.split(",");
                        String[] contentlist = contents.split(",");
                        String[] palnlist = palns.split(",");
                        if (greenlandlist.length>0){
                            for (int i = 0; i < greenlandlist.length; i++) {
                                if ((null==greenlandlist[i]||greenlandlist[i].equals("")||greenlandlist[i]=="")&&(null==contentlist[i]||contentlist[i].equals("")||contentlist[i]=="")&&(null==palnlist[i]||palnlist[i].equals("")||palnlist[i]=="")){
                                    continue;
                                }else{
                                    Plan_week_info plan_week_info = new Plan_week_info();
                                    plan_week_info.setI_pid(work_plan_week.getId());
                                    plan_week_info.setI_gid(Integer.parseInt(greenlandlist[i]));
                                    plan_week_info.setI_content(contentlist[i]);
                                    plan_week_info.setI_comp(palnlist[i]);
                                    plan_week_infoServie.save(plan_week_info);
                                }
                            }
                            if (null!=greenlandss){
                                DetachedCriteria criterias = DetachedCriteria.forClass(Plan_week_summary.class);
                                criterias.add(Restrictions.eq("su_pid", work_plan_week.getId()));
                                List<Plan_week_summary> byConditionss = plan_week_summaryService.findByConditions(criterias);
                                if(null!=byConditionss){
                                    for(Plan_week_summary plan_week_summary:byConditionss){
                                        plan_week_summaryService.deleteCass(plan_week_summary);
                                    }
                                    String[] greenlandlists = greenlandss.split(",");
                                    String[] contentlists = contentss.split(",");
                                    String[] palnlists = palnss.split(",");
                                    if (greenlandlists.length>0){
                                        for (int i = 0; i < greenlandlists.length; i++) {
                                            if ((null==greenlandlists[i]||greenlandlists[i].equals("")||greenlandlists[i]=="")&&(null==contentlists[i]||contentlists[i].equals("")||contentlists[i]=="")&&(null==palnlists[i]||palnlists[i].equals("")||palnlists[i]=="")){
                                                continue;
                                            }else{
                                                Plan_week_summary plan_week_summary = new Plan_week_summary();
                                                plan_week_summary.setSu_pid(work_plan_week.getId());
                                                plan_week_summary.setSu_gid(Integer.parseInt(greenlandlists[i]));
                                                plan_week_summary.setSu_content(contentlists[i]);
                                                plan_week_summary.setSu_comp(palnlists[i]);
                                                plan_week_summaryService.save(plan_week_summary);
                                            }
                                        }
                                    }
                                }else{
                                    String[] greenlandlists = greenlandss.split(",");
                                    String[] contentlists = contentss.split(",");
                                    String[] palnlists = palnss.split(",");
                                    if (greenlandlists.length>0){
                                        for (int i = 0; i < greenlandlists.length; i++) {
                                            if ((null==greenlandlists[i]||greenlandlists[i].equals("")||greenlandlists[i]=="")&&(null==contentlists[i]||contentlists[i].equals("")||contentlists[i]=="")&&(null==palnlists[i]||palnlists[i].equals("")||palnlists[i]=="")){
                                                continue;
                                            }else{
                                                Plan_week_summary plan_week_summary = new Plan_week_summary();
                                                plan_week_summary.setSu_pid(work_plan_week.getId());
                                                plan_week_summary.setSu_gid(Integer.parseInt(greenlandlists[i]));
                                                plan_week_summary.setSu_content(contentlists[i]);
                                                plan_week_summary.setSu_comp(palnlists[i]);
                                                plan_week_summaryService.save(plan_week_summary);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }else{
                        String[] greenlandlist = greenlands.split(",");
                        String[] contentlist = contents.split(",");
                        String[] palnlist = palns.split(",");
                        if (greenlandlist.length>0){
                            for (int i = 0; i < greenlandlist.length; i++) {
                                if ((null==greenlandlist[i]||greenlandlist[i].equals("")||greenlandlist[i]=="")&&(null==contentlist[i]||contentlist[i].equals("")||contentlist[i]=="")&&(null==palnlist[i]||palnlist[i].equals("")||palnlist[i]=="")){
                                    continue;
                                }else{
                                    Plan_week_info plan_week_info = new Plan_week_info();
                                    plan_week_info.setI_pid(work_plan_week.getId());
                                    plan_week_info.setI_gid(Integer.parseInt(greenlandlist[i]));
                                    plan_week_info.setI_content(contentlist[i]);
                                    plan_week_info.setI_comp(palnlist[i]);
                                    plan_week_infoServie.save(plan_week_info);
                                }
                            }
                            if (null!=greenlandss){
                                DetachedCriteria criterias = DetachedCriteria.forClass(Plan_week_summary.class);
                                criterias.add(Restrictions.eq("su_pid", work_plan_week.getId()));
                                List<Plan_week_summary> byConditionss = plan_week_summaryService.findByConditions(criterias);
                                if(null!=byConditionss){
                                    for(Plan_week_summary plan_week_summary:byConditionss){
                                        plan_week_summaryService.deleteCass(plan_week_summary);
                                    }
                                    String[] greenlandlists = greenlandss.split(",");
                                    String[] contentlists = contentss.split(",");
                                    String[] palnlists = palnss.split(",");
                                    if (greenlandlists.length>0){
                                        for (int i = 0; i < greenlandlists.length; i++) {
                                            if ((null==greenlandlists[i]||greenlandlists[i].equals("")||greenlandlists[i]=="")&&(null==contentlists[i]||contentlists[i].equals("")||contentlists[i]=="")&&(null==palnlists[i]||palnlists[i].equals("")||palnlists[i]=="")){
                                                continue;
                                            }else{
                                                Plan_week_summary plan_week_summary = new Plan_week_summary();
                                                plan_week_summary.setSu_pid(work_plan_week.getId());
                                                plan_week_summary.setSu_gid(Integer.parseInt(greenlandlists[i]));
                                                plan_week_summary.setSu_content(contentlists[i]);
                                                plan_week_summary.setSu_comp(palnlists[i]);
                                                plan_week_summaryService.save(plan_week_summary);
                                            }
                                        }
                                    }
                                }else{
                                    String[] greenlandlists = greenlandss.split(",");
                                    String[] contentlists = contentss.split(",");
                                    String[] palnlists = palnss.split(",");
                                    if (greenlandlists.length>0){
                                        for (int i = 0; i < greenlandlists.length; i++) {
                                            if ((null==greenlandlists[i]||greenlandlists[i].equals("")||greenlandlists[i]=="")&&(null==contentlists[i]||contentlists[i].equals("")||contentlists[i]=="")&&(null==palnlists[i]||palnlists[i].equals("")||palnlists[i]=="")){
                                                continue;
                                            }else{
                                                Plan_week_summary plan_week_summary = new Plan_week_summary();
                                                plan_week_summary.setSu_pid(work_plan_week.getId());
                                                plan_week_summary.setSu_gid(Integer.parseInt(greenlandlists[i]));
                                                plan_week_summary.setSu_content(contentlists[i]);
                                                plan_week_summary.setSu_comp(palnlists[i]);
                                                plan_week_summaryService.save(plan_week_summary);
                                            }
                                        }
                                    }
                                }
                            }
                        }else{
                            if (null!=greenlandss){
                                DetachedCriteria criterias = DetachedCriteria.forClass(Plan_week_summary.class);
                                criterias.add(Restrictions.eq("su_pid", work_plan_week.getId()));
                                List<Plan_week_summary> byConditionss = plan_week_summaryService.findByConditions(criterias);
                                if(null!=byConditionss){
                                    for(Plan_week_summary plan_week_summary:byConditionss){
                                        plan_week_summaryService.deleteCass(plan_week_summary);
                                    }
                                    String[] greenlandlists = greenlandss.split(",");
                                    String[] contentlists = contentss.split(",");
                                    String[] palnlists = palnss.split(",");
                                    if (greenlandlists.length>0){
                                        for (int i = 0; i < greenlandlists.length; i++) {
                                            if ((null==greenlandlists[i]||greenlandlists[i].equals("")||greenlandlists[i]=="")&&(null==contentlists[i]||contentlists[i].equals("")||contentlists[i]=="")&&(null==palnlists[i]||palnlists[i].equals("")||palnlists[i]=="")){
                                                continue;
                                            }else{
                                                Plan_week_summary plan_week_summary = new Plan_week_summary();
                                                plan_week_summary.setSu_pid(work_plan_week.getId());
                                                plan_week_summary.setSu_gid(Integer.parseInt(greenlandlists[i]));
                                                plan_week_summary.setSu_content(contentlists[i]);
                                                plan_week_summary.setSu_comp(palnlists[i]);
                                                plan_week_summaryService.save(plan_week_summary);
                                            }
                                        }
                                    }
                                }else{
                                    String[] greenlandlists = greenlandss.split(",");
                                    String[] contentlists = contentss.split(",");
                                    String[] palnlists = palnss.split(",");
                                    if (greenlandlists.length>0){
                                        for (int i = 0; i < greenlandlists.length; i++) {
                                            if ((null==greenlandlists[i]||greenlandlists[i].equals("")||greenlandlists[i]=="")&&(null==contentlists[i]||contentlists[i].equals("")||contentlists[i]=="")&&(null==palnlists[i]||palnlists[i].equals("")||palnlists[i]=="")){
                                                continue;
                                            }else{
                                                Plan_week_summary plan_week_summary = new Plan_week_summary();
                                                plan_week_summary.setSu_pid(work_plan_week.getId());
                                                plan_week_summary.setSu_gid(Integer.parseInt(greenlandlists[i]));
                                                plan_week_summary.setSu_content(contentlists[i]);
                                                plan_week_summary.setSu_comp(palnlists[i]);
                                                plan_week_summaryService.save(plan_week_summary);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return Layui.data(0, "修改成功", 1, Layui.addList(work_plan_week));
            }
        }
    }

    /*
     * @Author: 周权
     * @Description:周报删除
     * @Param:
     * @create: 2020/3/22 22:41
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "delete")
    public Layui delete(@RequestParam(value = "id") Integer id) {
        Work_plan_week byId = work_paln_weekService.findById(id);
        byId.setD_state(1);//设置日报状态为1 在列表页隐藏
        work_paln_weekService.saveOrUpdate(byId);
        return Layui.data(1, "删除成功", 1, null);
    }

    /*
     * @Author: 周权
     * @Description:周报图片上传
     * @Param:
     * @create: 2020/3/23 16:13
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "updateImg")
    public Layui updateImg(HttpServletRequest request,
                           @RequestParam(value = "file", required = false) MultipartFile[] file){
        ArrayList<String> urls = new ArrayList<>();
        if (null != file) {
            String image = FileUpload.picvideoupload("upload/picture", "file", request);
            urls.add("upload/picture/" + image);
        }
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int i = cal.get(Calendar.YEAR);
        int i1 = cal.get(Calendar.MONTH)+1;
        int i2 = cal.get(Calendar.DAY_OF_MONTH);
        int i3 = cal.get(Calendar.HOUR_OF_DAY);
        int i4 = cal.get(Calendar.MINUTE);
        int i5 = cal.get(Calendar.SECOND);
        String s = String.valueOf(i);
        String s1;
        if(i1<10){
            s1 = "0"+String.valueOf(i1);
        }else{
            s1 = String.valueOf(i1);
        }
        String s2;
        if(i2<10){
            s2 = "0"+String.valueOf(i2);
        }else{
            s2 = String.valueOf(i2);
        }
        String s3;
        if(i3<10){
            s3 = "0"+String.valueOf(i3);
        }else{
            s3 = String.valueOf(i3);
        }
        String s4;
        if(i4<10){
            s4 = "0"+String.valueOf(i4);
        }else{
            s4 = String.valueOf(i4);
        }
        String s5;
        if(i5<10){
            s5 = "0"+String.valueOf(i5);
        }else{
            s5 = String.valueOf(i5);
        }
        String time = s+"-"+s1+"-"+s2+" "+s3+":"+s4+":"+s5;
        return Layui.data(0,time,work_plan_week_imgService.getTotalCount(),urls);
    }

    /*
     * @Author: 周权
     * @Description:周报图片保存
     * @Param:
     * @create: 2020/3/24 10:48
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "savaImg")
    public Layui savaImg(@RequestParam(value = "data", required = false) String data) {
        JSONObject param = JSONObject.fromObject(data);
        if (param == null) {
            return Layui.data(1, "请求格式有误", 0, null);
        } else {
            String d_img = (String) param.get("d_img");
            if(!"".equals(d_img)){
                String[] d_imgs = d_img.split(",");
                String img_pid = (String) param.get("img_pid");
                int pid = Integer.parseInt(img_pid);
                DetachedCriteria criteria = DetachedCriteria.forClass(Work_plan_week_img.class);
                criteria.add(Restrictions.eq("img_pid", pid));
                List<Work_plan_week_img> list = work_plan_week_imgService.findByConditions(criteria);
                if (list.size() > 0) {
                    for (Work_plan_week_img work_plan_week_img : list) {
                        work_plan_week_imgService.delete(work_plan_week_img);
                    }
                    for (int i = 0; i < d_imgs.length; i++) {
                        Work_plan_week_img work_plan_week_img = new Work_plan_week_img();
                        work_plan_week_img.setImg_src(d_imgs[i]);
                        work_plan_week_img.setImg_pid(pid);
                        work_plan_week_img.setImg_createDate(new Date());
                        work_plan_week_imgService.save(work_plan_week_img);
                    }
                } else {
                    for (int i = 0; i < d_imgs.length; i++) {
                        Work_plan_week_img work_plan_week_img = new Work_plan_week_img();
                        work_plan_week_img.setImg_src(d_imgs[i]);
                        work_plan_week_img.setImg_pid(pid);
                        work_plan_week_img.setImg_createDate(new Date());
                        work_plan_week_imgService.save(work_plan_week_img);
                    }
                }
                //存入到日计划 方便修改时直接赋值多图
                Work_plan_week byId = work_paln_weekService.findById(pid);
                byId.setD_img(d_img);
                work_paln_weekService.saveMerge(byId);
                return Layui.data(0, "添加日报图片成功", 1, Layui.addList(byId));
            }else{
                String img_pid = (String) param.get("img_pid");
                int pid = Integer.parseInt(img_pid);
                DetachedCriteria criteria = DetachedCriteria.forClass(Work_plan_week_img.class);
                criteria.add(Restrictions.eq("img_pid", pid));
                List<Work_plan_week_img> list = work_plan_week_imgService.findByConditions(criteria);
                if (list.size() > 0) {
                    for (Work_plan_week_img work_plan_week_img : list) {
                        work_plan_week_imgService.delete(work_plan_week_img);
                    }
                }
                //存入到日计划 方便修改时直接赋值多图
                Work_plan_week byId = work_paln_weekService.findById(pid);
                byId.setD_img("");
                work_paln_weekService.saveMerge(byId);
                return Layui.data(0, "添加日报图片成功", null);
            }
        }
    }

    /*
     * @Author: 周权
     * @Description: 周报图片回显
     * @Param:
     * @create: 2020/3/24 12:29
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "findImg")
    public Layui findImg(@RequestParam(value = "img_pid") Integer img_pid){
        DetachedCriteria criteria = DetachedCriteria.forClass(Work_plan_week_img.class);
        criteria.add(Restrictions.eq("img_pid", img_pid));
        List<Work_plan_week_img> byConditions = work_plan_week_imgService.findByConditions(criteria);
        return Layui.data(0, "查询成功", work_plan_week_imgService.getTotalCount(), byConditions);
    }
}
